import { useNavigate } from "react-router-dom";
import { useEffect, useState } from "react";
import "./Go.css";
import bg from "../../assets/jiqi.png";

const Go = () => {
  const [time, settime] = useState(null);
  const [hit, sethit] = useState(3);

  const navigate = useNavigate();

  const gotologin = () => {
    setTimeout(() => {
      navigate("/login", { replace: true });
    }, 3000);
  };

  //   useEffect(() => {
  //     gotologin();
  //   }, []);

  console.log(hit);

  const starthit = () => {
    settime(
      setInterval(() => {
        sethit(hit - 1);
      }, 1000)
    );
  };

  useEffect(() => {
    starthit();
    gotologin();
    return () => {
      clearInterval(time);
    };
  }, [hit]);
  return (
    <div className="big">
      <div className="go">
        <div>即将进入登陆页,还剩下{hit}秒</div>
        <div onClick={gotologin}>立即进入</div>
      </div>
    </div>
  );
};

export default Go;
